package com.network.util.jdbc;

import java.sql.DriverManager;
import java.sql.SQLException;

public class MysqlDBO extends CommonDBO
{
	private String dataBaseName = "mysql";

	@Override
	protected Object clone() throws CloneNotSupportedException
	{
		MysqlDBO rtnCode = new MysqlDBO();
		rtnCode.setServerAddr(this.getServerAddr());
		rtnCode.setServerPort(this.getServerPort());
		rtnCode.setDataBaseName(this.getDataBaseName());
		rtnCode.setUserName(this.getUserName());
		rtnCode.setPassWord(this.getPassWord());
		return rtnCode;
	}

	@Override
	public boolean executeConnect()
	{
		boolean rtnCode = false;
		String strDriverName = "com.mysql.jdbc.Driver";
		String strDBUrl = "jdbc:mysql://" + getServerAddr() + ":" + getServerPort() + "/" + dataBaseName + "?user=" + getUserName() + "&password=" + getPassWord() + "&useUnicode=true&characterEncoding=UTF-8";
		try
		{
			Class.forName(strDriverName);
			setJdbcConn(DriverManager.getConnection(strDBUrl));
			rtnCode = true;
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		}
		return rtnCode;
	}

	@Override
	public boolean executeExport(Object... objs)
	{
		return false;
	}

	@Override
	public boolean executeImport(Object... objs)
	{
		
		return false;
	}

	@Override
	public String toString()
	{
		String rtnCode = "";
		rtnCode = "[" + getServerAddr() + "," + getServerPort() + "," + getDataBaseName() + "," + getUserName() + "]";
		return rtnCode;
	}

	public String getDataBaseName()
	{
		return this.dataBaseName;
	}

	public void setDataBaseName(String strDBName)
	{
		this.dataBaseName = strDBName;
	}
}
